<?php

namespace addons\AppVersions;

use Yii;
use yii\db\Migration;
use common\interfaces\AddonWidget;

/**
 * 升级数据库
 *
 * Class Upgrade
 * @package addons\AppVersions
 */
class Upgrade extends Migration implements AddonWidget
{
    /**
     * @var array
     */
    public $versions = [
        '1.0.0', // 默认版本
        '1.0.1',
    ];

    /**
    * @param $addon
    * @return mixed|void
    * @throws \yii\db\Exception
    */
    public function run($addon)
    {
        switch ($addon->version) {
            case '1.0.1' :
                 $this->addColumn('{{%addon_app_versions}}', 'cate_name', "varchar(100) NULL DEFAULT '' COMMENT '分类标识'");

                /* 创建表 */
                $this->createTable('{{%addon_app_cate}}', [
                    'id' => "int(11) NOT NULL AUTO_INCREMENT COMMENT '主键'",
                    'merchant_id' => "int(10) unsigned NULL DEFAULT '0' COMMENT '商户id'",
                    'name' => "varchar(100) NOT NULL DEFAULT '' COMMENT '标识'",
                    'title' => "varchar(50) NOT NULL DEFAULT '' COMMENT '标题'",
                    'sort' => "int(5) NULL DEFAULT '0' COMMENT '排序'",
                    'level' => "tinyint(1) NULL DEFAULT '1' COMMENT '级别'",
                    'pid' => "int(50) NULL DEFAULT '0' COMMENT '上级id'",
                    'tree' => "varchar(500) NOT NULL DEFAULT '' COMMENT '树'",
                    'status' => "tinyint(4) NULL DEFAULT '1' COMMENT '状态'",
                    'created_at' => "int(10) unsigned NOT NULL DEFAULT '0' COMMENT '创建时间'",
                    'updated_at' => "int(10) unsigned NOT NULL DEFAULT '0' COMMENT '更新时间'",
                    'PRIMARY KEY (`id`)'
                ], "ENGINE=MyISAM  DEFAULT CHARSET=utf8mb4 COMMENT='扩展_app分类表'");
                break;
        }
    }
}